
package facade;

import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import remoteEntity.Log;

/**
 * Manages the log table.
 * This version uses native mysql queries.
 * @author vho
 */
@Stateless
public class LogFacade extends AbstractFacade<Log> {
    @PersistenceContext(unitName = "filecityeePU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public LogFacade() {
        super(Log.class);
    }
    
    @Override
    public List findAll() {
        return em.createNativeQuery("select * from log order by date desc;",Log.class).getResultList();
    }

    public void log(String page, String msg, String level) {
        String query = "INSERT INTO log VALUES (null,'"+msg+"','"+page+"','"+level+"',NOW());"; //(null,'"+msg+"','"+page+"','"+level+"',NOW());";
        System.out.println(query);
        em.createNativeQuery(query).executeUpdate();
    }
    
}
